package org.wiztools.te;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import javax.swing.JEditorPane;
import javax.swing.JTextArea;
import jsyntaxpane.SyntaxKit;

public class MyEditor extends JEditorPane{
	MyEditor(){
		super();
                setEditorKit(new SyntaxKit(DEFAULT_KEYMAP));
	}
        
        public void append(String str){
            setText(new StringBuffer(this.getText()).append(str).toString());
        }
        
        /*public void replaceSelection(String str){
            setSelectedText(str);
        }*/
        
        public void insert(String str){
            // int line = getCaretLine();
            int caretPos = getCaretPosition();
            StringBuffer sb = new StringBuffer(getText());
            sb.insert(caretPos, str);
            setText(sb.toString());
        }
        
        public int getLineCount(){
            char[] str = this.getText().toCharArray();
            int count = 0;
            for(int i = 0; i <str.length; i++){
                if(str[i] == '\n'){
                    count++;
                }
            }
            return count;
        }
        
        /*public void write(Writer out) throws IOException{
            PrintWriter pw = new PrintWriter(out);
            pw.print(getText());
        }
        
        public void read(Reader in, Object desc) throws IOException{
            BufferedReader br = new BufferedReader(in);
            StringBuffer sb = new StringBuffer();
            String str = null;
            while((str = br.readLine())!=null){
                sb.append(str).append("\n");
            }
            setText(sb.toString());
        }*/
}
